<?php
class taoguaniostockorder_finder_iso{

	var $detail_basic = "出库单详情";
    var $detail_item = "出库单明细";

    var $addon_cols = "confirm";
    var $column_confirm='操作';
    var $column_confirm_width = "120";

 	function __construct(){
        if ($_GET['io']){
           $this->detail_basic = '入库单详情';
           $this->detail_item = '入库单明细';
        }else{
           $this->detail_basic = '出库单详情';
           $this->detail_item = '出库单明细';

        }
    }

    function column_confirm($row){
        $io = $_GET['io'];
        
    	if($_GET['act'] == 'search_iostockorder'){
            $id = $row['iso_id'];
            $button = <<<EOF
        &nbsp;&nbsp;<a href="index.php?app=purchase&ctl=admin_eo&act=printeo&p[0]=$id&t=$io" target="_bank" class="lnk">打印</a>
EOF;
            return $button;
        }
        $filter_data = array();
        if ($_isoST)
        foreach ($_isoST as $key=>$v){
            if (preg_match("/^_+/i",$key)) continue;
            $filter_data[$key] = $v;
        }
        $filter = urlencode(serialize($filter_data));
        $find_id = $_GET['_finder']['finder_id'];
        $iso_id = $row['iso_id'];


       if($_GET['io']){
       		$button = <<<EOF
            <a href="index.php?app=taoguaniostockorder&ctl=admin_iostockorder&act=iostockorder_confirm&p[0]=$iso_id&p[1]=1&filter=$filter&find_id=$find_id" target="_blank">入库确认</a>
EOF;

       }else{
       		$button = <<<EOF
            <a href="index.php?app=taoguaniostockorder&ctl=admin_iostockorder&act=iostockorder_confirm&p[0]=$iso_id&p[1]=0&filter=$filter&find_id=$find_id" target="_blank">出库确认</a>
EOF;

       }

       return $button;
    }


    function detail_basic($iso_id){		
        $render = app::get('taoguaniostockorder')->render();
        $isoObj = &app::get('taoguaniostockorder')->model('iso');
		
		//备注追加
        if($_POST){
            $iso_id = $_POST['iso_id'];
			$memo = htmlspecialchars($_POST['memo']);
            //取出原备注信息
            $oldmemo = $isoObj->dump(array('iso_id'=>$iso_id), 'memo');
            $oldmemo= $oldmemo['memo'];
            if ($oldmemo) $memo = $oldmemo.$memo.'；';
            $iso['memo'] = $memo;
			$iso['iso_id'] = $iso_id;
            $isoObj->save($iso);
        }

        $suObj = &app::get('purchase')->model('supplier');
        $brObj = &app::get('ome')->model('branch');
        $iso = $isoObj->dump($iso_id,'*',array('iso_items'=>array('*')));
        $total_num=0;
        if ($iso['iso_items'])
        foreach($iso['iso_items'] as $k=>$v){
            $total_num+=$v['nums'];
        }
        $su = $suObj->dump($iso['supplier_id'],'name');
        $br = $brObj->dump($iso['branch_id'], 'name');
		$iso['iso_id']   = $iso_id;
        $iso['branch_name']   = $br['name'];
        $iso['supplier_name'] = $su['name'];
        $iso['create_time'] = date("Y-m-d", $iso['create_time']);
        $iso['total_num']     = $total_num;
        $iso['memo'] = $iso['memo'];
        $render->pagedata['iso'] = $iso;
        $render->pagedata['amount'] = $iso['product_cost'] + $iso['iso_price'];

        if($_GET['io']){
        	return $render->fetch("admin/iostock/instock_detail.html");
        }else{
        	return $render->fetch("admin/iostock/outstock_detail.html");
        }

    }

    function detail_item($iso_id){
        $render = app::get('taoguaniostockorder')->render();
        $isoObj  = &app::get('taoguaniostockorder')->model('iso');
        $productObj   = &app::get('ome')->model('products');
        $iso = $isoObj->dump($iso_id,'iso_id',array('iso_items'=>array('*')));
		foreach($iso['iso_items'] as $k=>$order_item){
			$product = $productObj->dump($order_item['product_id'],'spec_info,barcode');
			$order_item['spec_info'] = $product['spec_info'];
			$order_item['barcode'] = $product['barcode'];
			$iso['iso_items'][$k] = $order_item;
		}

        $render->pagedata['iso_items'] = $iso['iso_items'];
     	if($_GET['io']){
        	return $render->fetch("admin/iostock/instock_item.html");
        }else{
        	return $render->fetch("admin/iostock/outstock_item.html");
        }
    }

}
?>